﻿Public Class uCBProducto
    Public Event ProductoAdicionado(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Private vCodProd As String
    Private rProducto As GBDZafiro.Producto
    Public ReadOnly Property oProducto As GBDZafiro.Producto
        Get
            Return rProducto
        End Get
    End Property
    Public ReadOnly Property CodigoProducto
        Get
            Return vCodProd
        End Get
    End Property

    Private Sub uCBProducto_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar = ChrW(Keys.Escape) Then
            Me.Visible = False
        End If
    End Sub

    Private Sub uCBProducto_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        vCodProd = ""
        Me.Visible = False
    End Sub

    Protected Overridable Sub ProductoAdicionado_Click(sender As System.Object, e As System.EventArgs) Handles Me.ProductoAdicionado

    End Sub

    Private Sub Buscar(sender As System.Object, e As System.EventArgs)
        vCodProd = tbCodigo.Text
        rProducto = New GBDZafiro.Producto
        rProducto = GBDZafiro.Producto.ConsxCodProducto(vCodProd)
        If Not String.IsNullOrEmpty(rProducto.codProducto) Then
            RaiseEvent ProductoAdicionado(sender, e)
        Else
            msnBox.msnExclamacion("El producto Digitado No existe")
            tbCodigo.Text = ""
            tbCodigo.Focus()
        End If
    End Sub

    Private Sub btCerrar_Click(sender As System.Object, e As System.EventArgs) Handles btCerrar.Click
        Me.Visible = False
    End Sub

    Private Sub tbCodigo_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles tbCodigo.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Buscar(sender, e)
        End If
        If e.KeyChar = ChrW(Keys.Escape) Then
            Me.Visible = False
        End If
    End Sub
End Class
